﻿import trees
import textrenderer
import lattice

def genRampedHalf(numOfIndividuals, fs, ts, depth=5):

    pop = []

    for i in range(numOfIndividuals/2):
        pop += [trees.generateRandomExpr(fs,ts,depth,'full')]
    for i in range(numOfIndividuals/2):
        pop += [trees.generateRandomExpr(fs,ts,depth,'grow')]

    return pop


def parsePopulationToLattice(population):
    overallLabels = {}
    for tree in population:
        labels = lattice.parseTreeToLattice(tree)
        for label in labels:
            if label in overallLabels:
                overallLabels[label] += 1
            else:
                overallLabels.update({label: 1})
    return overallLabels


if __name__ == '__main__':
    fs = ['+','-']
    ts = [1,2,'x']

    import dataset

    ds = dataset.DataSet('simple.xls', ['x','y'])
    p1 = genRampedHalf(10,fs,ts,3)

    for t in p1:
        #textrenderer.writeTreeToConsole(individual)
        #print individual
        #print evalSSEofIndividual(t, ds)
        pass

